def A(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True
def B(word1, word2, word3):
    C = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8,"nine": 9}
    number = C.get(word1, -1) * 100 + C.get(word2, -1) * 10 + C.get(word3, -1)
    if number < 100 or number > 999:
        print("Wrong input")
        return
    lower = number
    upper = number
    while True:
        if A(lower):
            print(lower)
            return
        if A(upper):
            print(upper)
            return
        lower -= 1
        upper += 1
words = input().split()
B(words[0], words[1], words[2])
